package com.zb.controller.web;

import com.zb.entity.vo.*;
import com.zb.result.Result;
import com.zb.service.ZjCustomerAuthorService;
import com.zb.service.ZjCustomerInfoService;
import com.zb.service.ZjCustomerService;
import com.zb.service.web.ConCustomerAuthorService;
import com.zb.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author WEN
 * @Date 2023/8/7 0007
 **/
@Api(tags = "前台系统类接口")
@RestController
@RequestMapping("/web/customer")
public class CustomerController {
    @Autowired
    private ZjCustomerService customerService;
    @Autowired
    private ZjCustomerInfoService customerInfoService;
    @Autowired
    private ZjCustomerAuthorService customerAuthorService;
    @Autowired
    private ConCustomerAuthorService conCustomerAuthorService;

    @ApiOperation("获取所有企业商家")
    @PostMapping("/getListCustomer")
    public Result getListCustomer(@RequestBody CustomerSelectVo selectVo) {
        return Result.success("获取所有企业成功！").data(customerService.getListCustomer(selectVo));
    }

    @ApiOperation("获取企业商家企业信息")
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable @ApiParam(value = "企业ID", required = true) Long id) {
        return Result .success("获取企业商家企业信息成功！").data("row", customerService.getInfo(id));
    }

    @ApiOperation("审核开通企业")
    @PutMapping("/checkOpen")
    public Result checkOpen(@RequestBody @Valid CustomerCheckOpenVo checkOpenVo) {
        customerService.checkOpen(checkOpenVo);
        return Result.success("企业审核开通成功！");
    }

    @ApiOperation("冻结企业")
    @PutMapping("/customerFreeze")
    public Result customerFreeze(@RequestBody @Valid CustomerFreezeVo freezeVo) {
        customerService.customerFreeze(3, freezeVo);
        return Result.success("冻结企业成功！");
    }

    @ApiOperation("解冻企业")
    @PutMapping("/customerUnFreeze")
    public Result customerUnFreeze(@RequestBody @Valid CustomerFreezeVo freezeVo) {
        customerService.customerFreeze(2, freezeVo);
        return Result.success("解冻企业成功！");
    }

    // 企业过期
    @ApiOperation("企业过期")
    @PutMapping("/customerExpire")
    public Result customerExpire(@RequestBody @Valid CustomerFreezeVo freezeVo) {
        customerService.customerFreeze(4, freezeVo);
        return Result.success("设置企业过期成功！");
    }

    // 续期(续费、延长到期时间)
    @ApiOperation("续期(续费、延长到期时间)")
    @PutMapping("/customerRenewal")
    public Result customerRenewal(@RequestBody @Valid CustomerRenewalVo renewalVo) {
        customerService.customerRenewal(renewalVo);
        return Result.success("企业续期(续费)成功");
    }

    // 更改版本 TODO
//    @ApiOperation("更改(升级)版本")
//    @PutMapping("/customerVersion")
//    public Result customerVersion() {
//        return Result.success("版本更改成功！");
//    }

    // 增加用户数
    @ApiOperation("更改企业用户数")
    @PutMapping("/customerUsers")
    public Result customerUsers(@RequestBody @Valid CustomerUsersVo usersVo) {
        customerInfoService.customerUsers(usersVo);
        return Result.success("更改企业用户数成功！");
    }

    // 账户余额、短信数量
    @ApiOperation("更改企业账户信息")
    @PutMapping("/customerAccount")
    public Result customerAccount(@RequestBody @Valid CustomerAccountVo accountVo) {
        customerInfoService.customerAccount(accountVo);
        return Result.success("企业账户信息更新成功！");
    }

    @ApiOperation("保存或修改商家模块菜单权限")
    @PostMapping("/saveCustomerAuthor/{id}")
    public Result saveCustomerAuthor(@PathVariable @ApiParam(value = "企业ID", required = true) Long id, @RequestBody @Valid CustomerAuthorSaveVo authorSaveVo) {
        conCustomerAuthorService.saveCustomerAuthor(id, authorSaveVo);
        return Result.success("保存商家模块菜单权限");
    }

    @ApiOperation("根据企业ID获取企业的模块菜单权限")
    @GetMapping("/getCustomerAuthor/{id}")
    public Result getCustomerAuthor(@PathVariable @ApiParam(value = "企业ID", required = true) Long id) {
        return Result.success("获取企业的模块菜单权限成功").data(PageUtil.rows(customerAuthorService.getCustomerAuthor(id)));
    }

}
